package com.zzxx.mapper;

import com.zzxx.pojo.Traveller;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface TravellerMapper {
	@Select("select * from traveller where id in (select travellerId from order_traveller where orderId = #{orderId})")
	public Traveller findByOrderId(String orderId);

	@Insert("insert into traveller (id, name, sex, phoneNum, credentialsType, credentialsNum, travellerType) " +
	"values (#{id},#{name},#{sex},#{phoneNum},#{credentialsType},#{credentialsNum},#{travellerType}) on duplicate key update " +
	"id=#{id},name=#{name},sex=#{sex},phoneNum=#{phoneNum},credentialsType=#{credentialsType},credentialsNum=#{credentialsNum},travellerType=#{travellerType}")
	void insertOrUpdate(Traveller n);

	@Delete("delete from order_traveller where orderId = #{id}")
	void deleteByOid(String id);

	@Select("set foreign_key_checks = #{status}")
	void setForeign_Key_Check(int status);

	@Insert("insert into order_traveller values (#{oid},#{tid}) ")
	void addOrderTraveller(@Param("oid") String oid, @Param("tid") String tid);

	@Select("select * from traveller where name = #{name} and sex = #{sex} and phoneNum = #{phoneNum} " +
	"and credentialsType = #{credentialsType} and credentialsNum = #{credentialsNum} and travellerType = #{travellerType}")
	Traveller findTraveller(Traveller traveller);
}
